package aau.client.geo;

public class Vector {
    public static Vector createWithDXDY(double dx, double dy) {
        double theta = Math.atan2(dy, dx);
        double scala = Math.sqrt(dx * dx + dy * dy);
        return new Vector(theta, scala);
    }

    public static Vector createWithPoints(Point from, Point to) {
        return createWithDXDY(to.x - from.x, to.y - from.y);
    }

    public double scala;

    public double theta;

    public Vector(double theta, double scala) {
        this.theta = theta;
        this.scala = scala;
    }

    public Vector add(Vector other) {
        return createWithDXDY(dx() + other.dx(), dy() + other.dy());
    }

    public double dx() {
        return Math.cos(this.theta) * this.scala;
    }

    public double dy() {
        return Math.sin(this.theta) * this.scala;
    }

    public double getScala() {
        return this.scala;
    }

    public double getTheta() {
        return this.theta;
    }

    public Vector rotate(double dTheta) {
        return new Vector(this.theta + dTheta, this.scala);
    }

    public Vector setScala(double scala) {
        this.scala = scala;
        return this;
    }

    public Vector setTheta(double theta) {
        this.theta = theta;
        return this;
    }

    public Vector multiply(double power) {
        return new Vector(this.theta, this.scala * power);
    }
}
